<script>
import api from '@/api'
import { Descriptions as YsDescriptions, Utils } from '@/components/YS'
export default {
  name: 'AdminAdminDetail',
  components: {
    YsDescriptions
  },
  props: {
    id: {
      type: Number,
      default: 0
    }
  },
  data () {
    const _this = this
    return {
      params: {},
      descriptions: {
        title: '管理员详情',
        fields: {
          id: this.__('ID'),
          role_text: this.__('角色'),
          email: this.__('邮箱'),
          nickname: this.__('昵称'),
          username: this.__('用户名称'),
          avatar: {
            title: this.__('头像'),
            formatter (value) {
              return Utils.image.call(this, value)
            }
          },
          loginfailure: this.__('登录失败次数'),
          status_text: this.__('状态'),
          token_expiry_time: this.__('Token失效时间'),
          login_time: this.__('登录时间'),
          update_time: this.__('更新时间'),
          create_time: this.__('创建时间')
        },
        data () {
          _this.params.id = _this.id || _this.$route.query.id
          return api.admin.admin.detail(_this.params).then(response => {
            return Promise.resolve(response.data.data.row)
          }).catch(error => {
            return Promise.reject(error)
          })
        }
      }
    }
  },
  created () {
    this.params.id = this.id || this.$route.query.id
  },
  render () {
    const props = this.descriptions
    return <ys-descriptions { ...{ props } } ></ys-descriptions>
  }
}
</script>
